import vt
import os
import time

class VirusScan:
    def __init__(self):
        self.client = vt.Client("f712cc4060b2403e9b72218eb5789e4df8348ee1bef26e7eb9f596e23a190a10")
        self.analysis = None

    def scan(self,path):
        file_list = os.listdir(path)
        for file in file_list:
            res = self.scan_file(os.path.join(path,file))
            if res["suspicious"] > 0 and res["malicious"] > 0:
                os.remove(os.path.join(path,file))

    def scan_file(self,file_path):
        with open(file_path, "rb") as f:
            analysis = self.client.scan_file(f)
            while True:
                analysis = self.client.get_object("/analyses/{}", analysis.id)
                print(analysis.status)
                if analysis.status == "completed":
                    self.analysis = analysis.to_dict()
                    return self.analysis["attributes"]["stats"]
                time.sleep(5)

if __name__ == "__main__":
    test = VirusScan()
    res = test.scan_file("test.txt")
    print(res)
